/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.comac.ins.common.core.exception.base.BaseException;
import com.comac.ins.common.core.utils.MapstructUtils;
import com.comac.ins.common.core.utils.StringUtils;
import com.comac.ins.common.mybatis.core.page.PageQuery;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.isfd.domain.IsfdMetalMaterialStaticStrengthAnalysis;
import com.comac.ins.isfd.domain.bo.IsfdMetalMaterialStaticStrengthAnalysisBo;
import com.comac.ins.isfd.domain.bo.query.IsfdMetalMaterialStaticStrengthAnalysisQueryBo;
import com.comac.ins.isfd.domain.vo.IsfdMetalMaterialStaticStrengthAnalysisVo;
import com.comac.ins.isfd.mapper.IsfdMetalMaterialStaticStrengthAnalysisMapper;
import com.comac.ins.isfd.service.IIsfdMetalMaterialStaticStrengthAnalysisService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 金属材料-静强度分析Service业务层处理
 *
 * @author hxloongs
 * @date 2025-08-20
 */
@RequiredArgsConstructor
@Service
public class IsfdMetalMaterialStaticStrengthAnalysisServiceImpl implements IIsfdMetalMaterialStaticStrengthAnalysisService {

    @Autowired
    private IsfdMetalMaterialStaticStrengthAnalysisMapper baseMapper;

    @Override
    public IsfdMetalMaterialStaticStrengthAnalysisVo queryById(Long id) {
        return baseMapper.selectVoById(id);
    }

    @Override
    public TableDataInfo<IsfdMetalMaterialStaticStrengthAnalysisVo> queryPageList(IsfdMetalMaterialStaticStrengthAnalysisQueryBo queryBo) {
        PageQuery pageQuery = new PageQuery();
        pageQuery.setPageNum(queryBo.getPageNum());
        pageQuery.setPageSize(queryBo.getPageSize());
        LambdaQueryWrapper<IsfdMetalMaterialStaticStrengthAnalysis> lqw = buildQueryWrapper(queryBo);
        Page<IsfdMetalMaterialStaticStrengthAnalysisVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    @Override
    public List<IsfdMetalMaterialStaticStrengthAnalysisVo> queryList(IsfdMetalMaterialStaticStrengthAnalysisBo bo) {
        LambdaQueryWrapper<IsfdMetalMaterialStaticStrengthAnalysis> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }


    private LambdaQueryWrapper<IsfdMetalMaterialStaticStrengthAnalysis> buildQueryWrapper(IsfdMetalMaterialStaticStrengthAnalysisQueryBo queryBo) {
        LambdaQueryWrapper<IsfdMetalMaterialStaticStrengthAnalysis> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(queryBo.getName()), IsfdMetalMaterialStaticStrengthAnalysis::getName, queryBo.getName());
        lqw.eq(queryBo.getMid() != null, IsfdMetalMaterialStaticStrengthAnalysis::getMid, queryBo.getMid());
        lqw.eq(queryBo.getE() != null, IsfdMetalMaterialStaticStrengthAnalysis::getE, queryBo.getE());
        lqw.eq(queryBo.getG() != null, IsfdMetalMaterialStaticStrengthAnalysis::getG, queryBo.getG());
        lqw.eq(queryBo.getNu() != null, IsfdMetalMaterialStaticStrengthAnalysis::getNu, queryBo.getNu());
        lqw.eq(queryBo.getRho() != null, IsfdMetalMaterialStaticStrengthAnalysis::getRho, queryBo.getRho());
        lqw.eq(queryBo.getA() != null, IsfdMetalMaterialStaticStrengthAnalysis::getA, queryBo.getA());
        lqw.eq(queryBo.getTref() != null, IsfdMetalMaterialStaticStrengthAnalysis::getTref, queryBo.getTref());
        lqw.eq(queryBo.getGe() != null, IsfdMetalMaterialStaticStrengthAnalysis::getGe, queryBo.getGe());
        lqw.eq(queryBo.getSt() != null, IsfdMetalMaterialStaticStrengthAnalysis::getSt, queryBo.getSt());
        lqw.eq(queryBo.getSc() != null, IsfdMetalMaterialStaticStrengthAnalysis::getSc, queryBo.getSc());
        lqw.eq(queryBo.getSs() != null, IsfdMetalMaterialStaticStrengthAnalysis::getSs, queryBo.getSs());
        lqw.orderByDesc(IsfdMetalMaterialStaticStrengthAnalysis::getCreateTime);
        return lqw;
    }

    private LambdaQueryWrapper<IsfdMetalMaterialStaticStrengthAnalysis> buildQueryWrapper(IsfdMetalMaterialStaticStrengthAnalysisBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<IsfdMetalMaterialStaticStrengthAnalysis> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(bo.getName()), IsfdMetalMaterialStaticStrengthAnalysis::getName, bo.getName());
        lqw.eq(bo.getMid() != null, IsfdMetalMaterialStaticStrengthAnalysis::getMid, bo.getMid());
        lqw.eq(bo.getE() != null, IsfdMetalMaterialStaticStrengthAnalysis::getE, bo.getE());
        lqw.eq(bo.getG() != null, IsfdMetalMaterialStaticStrengthAnalysis::getG, bo.getG());
        lqw.eq(bo.getNu() != null, IsfdMetalMaterialStaticStrengthAnalysis::getNu, bo.getNu());
        lqw.eq(bo.getRho() != null, IsfdMetalMaterialStaticStrengthAnalysis::getRho, bo.getRho());
        lqw.eq(bo.getA() != null, IsfdMetalMaterialStaticStrengthAnalysis::getA, bo.getA());
        lqw.eq(bo.getTref() != null, IsfdMetalMaterialStaticStrengthAnalysis::getTref, bo.getTref());
        lqw.eq(bo.getGe() != null, IsfdMetalMaterialStaticStrengthAnalysis::getGe, bo.getGe());
        lqw.eq(bo.getSt() != null, IsfdMetalMaterialStaticStrengthAnalysis::getSt, bo.getSt());
        lqw.eq(bo.getSc() != null, IsfdMetalMaterialStaticStrengthAnalysis::getSc, bo.getSc());
        lqw.eq(bo.getSs() != null, IsfdMetalMaterialStaticStrengthAnalysis::getSs, bo.getSs());
        return lqw;
    }

    @Override
    public Boolean insertByBo(IsfdMetalMaterialStaticStrengthAnalysisBo bo) {
        IsfdMetalMaterialStaticStrengthAnalysis add = MapstructUtils.convert(bo, IsfdMetalMaterialStaticStrengthAnalysis.class);
        return baseMapper.insert(add) > 0;
    }

    @Override
    public Boolean updateByBo(IsfdMetalMaterialStaticStrengthAnalysisBo bo) {
        if (bo.getId() == null) {
            throw new BaseException("主键id不能为空");
        }
        IsfdMetalMaterialStaticStrengthAnalysis update = MapstructUtils.convert(bo, IsfdMetalMaterialStaticStrengthAnalysis.class);
        return baseMapper.updateById(update) > 0;
    }

    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids) {
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
